<template>
  <div class="login-body">
    <div class="login-container">
      <div class="head">
        <!-- <img class="logo" src="https://s.yezgea02.com/1582958061265/mlogo.png" /> -->
        <div class="name">
          <div class="title">sabre 沙豹</div>
          <div class="tips">后台管理系统</div>
        </div>
      </div>
      <el-form label-position="top" :rules="state.rules" :model="state.ruleForm" ref="loginForm" class="login-form">
        <el-form-item label="账号" prop="username">
          <el-input type="text" v-model.trim="state.ruleForm.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" class="form-bottom">
          <el-input type="password" v-model.trim="state.ruleForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item class="form-bottom">
          <!-- <div style="color: #333">登录表示您已同意<a>《服务条款》</a></div> -->
          <el-button :loading="loginloding" style="width: 100%" type="primary" @click="submitForm">立即登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import axios from '@/utils/axios'
import md5 from 'js-md5'
import { reactive, ref } from 'vue'
import { localSet } from '@/utils'
const loginForm = ref(null)
const loginloding = ref(false)
const state = reactive({
  ruleForm: {
    username: '',
    password: ''
  },
  checked: true,
  rules: {
    username: [
      { required: 'true', message: '账户不能为空', trigger: 'blur' }
    ],
    password: [
      { required: 'true', message: '密码不能为空', trigger: 'blur' }
    ]
  }
})
const submitForm = async () => {
  loginForm.value.validate((valid) => {
    if (valid) {
      axios.post('/adminUser/login', {
        userName: state.ruleForm.username || '',
        passwordMd5: md5(state.ruleForm.password)
      }).then(res => {
        localSet('token', res)
        loginloding.value = false
        window.location.href = '/'
      })
    } else {
      console.log('error submit!!')
      return false;
    }
  })
}
const resetForm = () => {
  loginForm.value.resetFields();
}
</script>

<style scoped>
@keyframes gradient {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

.form-bottom {
  margin-top: 1.5rem;
}

.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  background: linear-gradient(135deg,#17ead9,#6078ea);
  /* background-size: 600% 600%; */
  /* animation: gradient 5s ease infinite; */
}

.login-container {
  width: 420px;
  height: 500px;
  background-color: #ffffffc7;
  backdrop-filter: blur(10px);
  border-radius: 4px;
  box-shadow: 0px 21px 41px 0px rgba(0, 0, 0, 0.2);
}

.head {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px 0 20px 0;
}

.head .name {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.head img {
  width: 100px;
  height: 100px;
  margin-right: 20px;
}

.head .title {
  font-size: 28px;
  color: #0870c0;
  font-weight: bold;
  margin-bottom: 0.5rem;
  user-select: none;
}

.head .tips {
  user-select: none;
  font-size: 18px;
  color: #7b7b7b;
}

.login-form {
  width: 70%;
  margin: 0 auto;
}

.login-form>>>.el-form--label-top .el-form-item__label {
  padding: 0;
}

.login-form>>>.el-form-item {
  margin-bottom: 0;
}</style>